package com.hxx.controller;

import com.alibaba.fastjson2.JSON;
import com.hxx.domain.Person;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/emp/hxx.do")
public class PersonController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        Person person = new Person(1, "张三", "男", 18);
        //json
        String jsonString = JSON.toJSONString(person);
        //响应
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }
}

























